﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Email.Data;

namespace Email
{
    public partial class RegisterForm : Form
    {
        private UserManager _userManager;
        public RegisterForm(UserManager userManager)
        {
            InitializeComponent();
            _userManager = userManager;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string username = textBox1.Text;
            string password = textBox2.Text;
            string smtpcode=textBox3.Text;

            if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
            {
                MessageBox.Show("用户名和密码不能为空。");
                return;
            }

            try
            {
                _userManager.RegisterUser(username, password, smtpcode);
                MessageBox.Show("注册成功！");
                Form1 form1 = new Form1(username, password, smtpcode);
                this.Close(); // 关闭当前窗口
                form1.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show("注册失败: " + ex.Message);
            }
        }
    }
}
